package com.baidu.mapapi;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.Rect;
import android.os.Build.VERSION;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import java.lang.reflect.Method;
import java.nio.ShortBuffer;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class a extends View
{
  private static Method H = null;
  private static Method I = null;
  private static Method J = null;
  private float A;
  private float B;
  private float C;
  private int D;
  private int E;
  private boolean F;
  private Paint G;
  private MapView.a K;
  boolean a;
  int b;
  int c;
  int d;
  double e;
  int f;
  int g;
  private Bitmap h = null;
  private ShortBuffer i = null;
  private short[] j = null;
  private int k;
  private int l;
  private int m;
  private int n;
  private MapView o;
  private List<Overlay> p;
  private int q;
  private int r;
  private int s;
  private boolean t;
  private long u;
  private long v;
  private long w;
  private float x;
  private float y;
  private float z;

  public a(Context paramContext, MapView paramMapView)
  {
    super(paramContext);
    this.a = false;
    this.k = 0;
    this.l = 0;
    this.m = 0;
    this.n = 0;
    this.o = null;
    this.p = new ArrayList();
    this.q = 0;
    this.r = 0;
    this.s = 0;
    this.b = 0;
    this.c = 0;
    this.d = 0;
    this.t = false;
    this.u = 0L;
    this.v = 0L;
    this.w = 0L;
    this.e = 1D;
    this.D = 0;
    this.f = 0;
    this.g = 0;
    this.E = 0;
    this.F = false;
    this.G = new Paint();
    this.K = MapView.a.b;
    this.o = paramMapView;
    this.G.setColor(-7829368);
    this.G.setStyle(Paint.Style.STROKE);
  }

  private void c(Canvas paramCanvas)
  {
  }

  private void d(Canvas paramCanvas)
  {
    long l1 = 1000L * System.nanoTime() / 1000000000L;
    Iterator localIterator = this.p.iterator();
    while (localIterator.hasNext())
      ((Overlay)localIterator.next()).draw(paramCanvas, this.o, false, l1);
  }

  public final List<Overlay> a()
  {
    return this.p;
  }

  public void a(int paramInt1, int paramInt2, int paramInt3)
  {
    this.E = (paramInt1 + this.E);
    this.D = 3;
    if ((paramInt2 == 0) && (paramInt3 == 0))
    {
      this.f = (this.h.getWidth() / 2);
      this.g = (this.h.getHeight() / 2);
    }
    while (true)
    {
      invalidate();
      return;
      this.f = paramInt2;
      this.g = paramInt3;
    }
  }

  public void a(int paramInt1, int paramInt2, int paramInt3, int paramInt4)
  {
    if ((paramInt4 <= 0) || (paramInt3 <= 0));
    while (true)
    {
      int i1;
      int i2;
      do
      {
        return;
        i1 = 4 * (paramInt3 + 3) / 4;
        i2 = 4 * (paramInt4 + 3) / 4;
      }
      while ((this.r == i1) && (this.s == i2));
      Iterator localIterator = this.p.iterator();
      while (localIterator.hasNext())
        ((Overlay)localIterator.next()).a(paramInt1, paramInt2, i1, i2);
      int i3 = 2 * i1 * i2;
      if (i3 > this.q)
      {
        this.j = new short[i3];
        this.i = ShortBuffer.allocate(i3);
        this.q = i3;
      }
      this.h = Bitmap.createBitmap(i1, i2, Bitmap.Config.RGB_565);
      Mj.renderUpdateScreen(this.j, i1, i2);
      this.r = i1;
      this.s = i2;
    }
  }

  protected void a(Canvas paramCanvas)
  {
    paramCanvas.drawRGB(192, 192, 192);
    Matrix localMatrix = new Matrix();
    if (this.e != 1D)
    {
      double d1 = Math.abs(this.e);
      localMatrix.postScale((float)d1, (float)d1, this.f, this.g);
      localMatrix.postTranslate(this.c, this.d);
      paramCanvas.drawBitmap(this.h, localMatrix, null);
    }
    while (true)
    {
      return;
      paramCanvas.drawBitmap(this.h, this.c, this.d, null);
    }
  }

  void a(boolean paramBoolean)
  {
    this.F = paramBoolean;
  }

  void a(boolean paramBoolean, int paramInt, Rect paramRect)
  {
    super.onFocusChanged(paramBoolean, paramInt, paramRect);
  }

  boolean a(int paramInt, KeyEvent paramKeyEvent)
  {
    boolean bool = false;
    int i1 = this.p.size() - 1;
    while (true)
    {
      if (i1 >= 0)
      {
        bool = ((Overlay)this.p.get(i1)).onKeyDown(paramInt, paramKeyEvent, this.o);
        if (!(bool))
          break label50;
      }
      return bool;
      label50: --i1;
    }
  }

  boolean a(MotionEvent paramMotionEvent)
  {
    int i1;
    int i3;
    if (Integer.parseInt(Build.VERSION.SDK) <= 4)
    {
      i1 = 1;
      if (i1 != 2)
        break label459;
    }
    try
    {
      Method localMethod1 = J;
      Object[] arrayOfObject1 = new Object[1];
      arrayOfObject1[0] = Integer.valueOf(0);
      this.x = ((Float)localMethod1.invoke(paramMotionEvent, arrayOfObject1)).floatValue();
      Method localMethod2 = I;
      Object[] arrayOfObject2 = new Object[1];
      arrayOfObject2[0] = Integer.valueOf(0);
      this.y = ((Float)localMethod2.invoke(paramMotionEvent, arrayOfObject2)).floatValue();
      Method localMethod3 = J;
      Object[] arrayOfObject3 = new Object[1];
      arrayOfObject3[0] = Integer.valueOf(1);
      this.z = ((Float)localMethod3.invoke(paramMotionEvent, arrayOfObject3)).floatValue();
      Method localMethod4 = I;
      Object[] arrayOfObject4 = new Object[1];
      arrayOfObject4[0] = Integer.valueOf(1);
      this.A = ((Float)localMethod4.invoke(paramMotionEvent, arrayOfObject4)).floatValue();
      this.C = ((float)Math.sqrt((this.x - this.z) * (this.x - this.z) + (this.y - this.A) * (this.y - this.A)) / 2F);
      if (this.D == 0)
      {
        if (this.C > 30.0F * Mj.j)
        {
          this.t = false;
          this.f = (int)((this.x + this.z) / 2F - this.c);
          this.g = (int)((this.y + this.A) / 2F - this.d);
          this.B = this.C;
          this.D = 1;
        }
        if (this.D == 0)
          break label479;
        i3 = 0;
        label1175: label538: label459: label1107: label479: return i3;
      }
    }
    catch (Exception localException2)
    {
      try
      {
        if (H == null)
        {
          Class localClass = Class.forName("android.view.MotionEvent");
          H = localClass.getMethod("getPointerCount", (Class[])null);
          Class[] arrayOfClass1 = new Class[1];
          arrayOfClass1[0] = Integer.TYPE;
          J = localClass.getMethod("getX", arrayOfClass1);
          Class[] arrayOfClass2 = new Class[1];
          arrayOfClass2[0] = Integer.TYPE;
          I = localClass.getMethod("getY", arrayOfClass2);
        }
        int i13 = ((Integer)H.invoke(paramMotionEvent, new Object[0])).intValue();
        i1 = i13;
      }
      catch (Exception localException1)
      {
        int i8;
        int i9;
        while (true)
        {
          while (true)
          {
            while (true)
            {
              while (true)
              {
                do
                  while (true)
                  {
                    while (true)
                    {
                      while (true)
                      {
                        localException1.printStackTrace();
                        i1 = 0;
                      }
                      localException2 = localException2;
                      localException2.printStackTrace();
                    }
                    this.e = (this.C / this.B);
                    invalidate();
                  }
                while (this.D != 1);
                this.D = 2;
                invalidate();
              }
              int i2 = this.p.size() - 1;
              while (true)
              {
                while (true)
                {
                  if (i2 < 0)
                    break label538;
                  if (!(((Overlay)this.p.get(i2)).onTouchEvent(paramMotionEvent, this.o)))
                    break;
                  i3 = 1;
                }
                i2 += -1;
              }
              switch (paramMotionEvent.getAction())
              {
              default:
                i3 = 0;
              case 0:
              case 1:
              case 2:
              }
            }
            this.k = (int)paramMotionEvent.getX();
            this.l = (int)paramMotionEvent.getY();
            this.c = 0;
            this.d = 0;
            this.t = true;
            Mj.MapProc(4, (int)paramMotionEvent.getX(), (int)paramMotionEvent.getY());
            i3 = 1;
          }
          if (this.t)
            break;
          i3 = 1;
        }
        this.t = false;
        if ((this.c != 0) || (this.d != 0))
        {
          this.c = 0;
          this.d = 0;
        }
        int i4 = (int)paramMotionEvent.getX();
        int i5 = (int)paramMotionEvent.getY();
        int i6 = (int)(20.0F * Mj.j);
        if ((this.w - this.v < 1000L) && (Math.abs(i4 - this.k) < i6) && (Math.abs(i5 - this.l) < i6))
          this.u = (1L + this.u);
        if (this.u == 1L)
        {
          this.v = System.currentTimeMillis();
          int i7 = (int)(10.0F * Mj.j);
          if ((Math.abs(this.k - i4) >= i7) || (Math.abs(this.l - i5) >= i7))
            break label1175;
          int i11 = this.k;
          int i12 = this.l;
          i8 = i11;
          i9 = i12;
        }
        while (true)
        {
          while (true)
          {
            do
            {
              do
              {
                this.m = i8;
                this.n = i9;
                Mj.MapProc(5, i8, i9);
              }
              while ((Math.abs(i8 - this.k) >= 20) || (Math.abs(i9 - this.l) >= 20));
              int i10 = this.p.size() - 1;
              while (true)
              {
                boolean bool;
                if (i10 < 0);
                Overlay localOverlay = (Overlay)this.p.get(i10);
                GeoPoint localGeoPoint = this.o.getProjection().fromPixels((int)paramMotionEvent.getX(), (int)paramMotionEvent.getY());
                if (localOverlay instanceof ItemizedOverlay)
                  bool = ((ItemizedOverlay)localOverlay).onTap(localGeoPoint, this.o);
                while (true)
                {
                  while (true)
                  {
                    while (true)
                    {
                      do
                        while (true)
                        {
                          if (!(bool))
                            break label1107;
                          i3 = 1;
                        }
                      while (this.u < 2L);
                      this.w = System.currentTimeMillis();
                      if ((this.w - this.v >= 1000L) || (Math.abs(this.m - i4) >= i6) || (Math.abs(this.n - i5) >= i6))
                        break;
                      if (this.o.getZoomLevel() < 18)
                        a(1, i4, i5);
                      this.u = 0L;
                      this.v = 0L;
                      this.w = 0L;
                    }
                    this.u = 0L;
                    this.v = 0L;
                    this.w = 0L;
                  }
                  bool = localOverlay.onTap(localGeoPoint, this.o);
                }
                i10 += -1;
              }
            }
            while (this.t != true);
            this.c = ((int)paramMotionEvent.getX() - this.k);
            this.d = ((int)paramMotionEvent.getY() - this.l);
            invalidate();
            Mj.MapProc(3, (int)paramMotionEvent.getX(), (int)paramMotionEvent.getY());
          }
          i8 = i4;
          i9 = i5;
        }
      }
    }
  }

  protected void b(Canvas paramCanvas)
  {
    a(paramCanvas);
    if ((!(this.F)) && (this.e != 1D));
    while (true)
    {
      while (true)
      {
        while (true)
        {
          while (true)
          {
            return;
            switch (1.a[this.K.ordinal()])
            {
            default:
              c(paramCanvas);
              d(paramCanvas);
            case 1:
            case 2:
            case 3:
            }
          }
          d(paramCanvas);
        }
        d(paramCanvas);
        c(paramCanvas);
      }
      c(paramCanvas);
      d(paramCanvas);
    }
  }

  boolean b()
  {
    int i2;
    int i1 = this.p.size() - 1;
    if (i1 >= 0)
      if (((Overlay)this.p.get(i1)) instanceof MyLocationOverlay)
        i2 = 1;
    while (true)
    {
      while (true)
      {
        return i2;
        --i1;
      }
      i2 = 0;
    }
  }

  boolean b(int paramInt, KeyEvent paramKeyEvent)
  {
    boolean bool = false;
    int i1 = this.p.size() - 1;
    while (true)
    {
      if (i1 >= 0)
      {
        bool = ((Overlay)this.p.get(i1)).onKeyUp(paramInt, paramKeyEvent, this.o);
        if (!(bool))
          break label50;
      }
      return bool;
      label50: --i1;
    }
  }

  boolean b(MotionEvent paramMotionEvent)
  {
    boolean bool = false;
    int i1 = this.p.size() - 1;
    while (true)
    {
      if (i1 >= 0)
      {
        bool = ((Overlay)this.p.get(i1)).onTrackballEvent(paramMotionEvent, this.o);
        if (!(bool))
          break label46;
      }
      return bool;
      label46: --i1;
    }
  }

  protected void onDraw(Canvas paramCanvas)
  {
    this.o.c();
    switch (this.D)
    {
    default:
      b(paramCanvas);
    case 0:
    case 1:
    case 2:
    case 3:
    }
    while (true)
    {
      while (true)
      {
        int i1;
        int i2;
        double d3;
        while (true)
        {
          while (true)
          {
            return;
            if ((this.j != null) && (this.a == true))
            {
              this.c = 0;
              this.d = 0;
              this.i.put(this.j);
              this.i.rewind();
              this.h.copyPixelsFromBuffer(this.i);
              this.a = false;
              this.e = 1D;
            }
            b(paramCanvas);
          }
          b(paramCanvas);
        }
        double d2 = Math.log(this.e) / Math.log(2.0D);
        if (d2 >= 0D)
        {
          i1 = (int)(d2 + 0.5D);
          i2 = (int)(10.0D * (i1 - d2));
          if (i2 == 0)
            break label248;
          if (i2 <= 0)
            break label232;
          d3 = d2 + 0.10000000000000001D;
          (i2 - 1);
        }
        while (true)
        {
          while (true)
          {
            while (true)
            {
              this.e = Math.pow(2.0D, d3);
              b(paramCanvas);
              postInvalidate();
            }
            i1 = (int)(d2 - 0.5D);
          }
          label232: d3 = d2 - 0.10000000000000001D;
          (i2 + 1);
        }
        label248: this.e = Math.pow(2.0D, i1);
        b(paramCanvas);
        if (d2 != 0D)
        {
          Bundle localBundle2 = new Bundle();
          localBundle2.putInt("act", 1001);
          localBundle2.putInt("opt", 10020600);
          localBundle2.putInt("level", i1);
          localBundle2.putInt("x", this.f);
          localBundle2.putInt("y", this.g);
          int i3 = this.f + this.c - this.r / 2;
          int i4 = this.g + this.d - this.s / 2;
          localBundle2.putInt("dx", i3);
          localBundle2.putInt("dy", i4);
          Mj.sendBundle(localBundle2);
        }
        this.D = 0;
      }
      double d1 = Math.log(this.e) / Math.log(2.0D);
      if (this.E > 0)
        this.e += Math.pow(2.0D, (int)d1) / 10.0D;
      while (true)
      {
        do
          while (true)
          {
            if ((((this.e >= 2 * this.E) || (this.e <= 0D))) && (((this.E >= 0) || (this.e <= -1.0F / 2 * this.E))))
              break label547;
            b(paramCanvas);
            postInvalidate();
          }
        while (this.E >= 0);
        this.e -= Math.pow(2.0D, (int)d1) / 20.0D;
      }
      label547: b(paramCanvas);
      Bundle localBundle1 = new Bundle();
      localBundle1.putInt("act", 1001);
      localBundle1.putInt("opt", 10020600);
      localBundle1.putInt("level", this.E);
      localBundle1.putInt("x", this.f);
      localBundle1.putInt("y", this.g);
      localBundle1.putInt("dx", 0);
      localBundle1.putInt("dy", 0);
      Mj.sendBundle(localBundle1);
      this.D = 0;
      this.E = 0;
    }
  }

  protected void onLayout(boolean paramBoolean, int paramInt1, int paramInt2, int paramInt3, int paramInt4)
  {
    super.onLayout(paramBoolean, paramInt1, paramInt2, paramInt3, paramInt4);
    a(paramInt1, paramInt2, paramInt3 - paramInt1, paramInt4 - paramInt2);
  }
}